"use strict";
const { Model } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
  class message extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      message.belongsTo(models.Staff, {
        foreignKey: "creator_id", //外键，产生这条消息的用户id
      });
      // define association here
    }
  }
  message.init(
    {
      content: DataTypes.STRING, //消息内容
      type: DataTypes.STRING, //类型
      read: {
        //已读用户的id，用,分开拼接成字符串
        type: DataTypes.TEXT,
        defaultValue: "",
      },
      deleted: {
        //已读的用户的id将会加到该字符串中
        type: DataTypes.TEXT,
        defaultValue: "",
      },
    },
    {
      sequelize,
      modelName: "message",
      tableName: "messages",
    }
  );
  return message;
};
